package com.huaxin.hxmodulestatisticalanalysis.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.huaxin.hxmodulestatisticalanalysis.dto.ResponseCode;
import com.huaxin.hxmodulestatisticalanalysis.dto.ResponseResult;
import com.huaxin.hxmodulestatisticalanalysis.dto.response.*;
import com.huaxin.hxmodulestatisticalanalysis.service.DataAnalysisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Tag(name = "统计分析")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/statisticalanalysis/dataAnalysis")
public class DataAnalysisController {
    private final DataAnalysisService dataAnalysisService;

    @Operation(summary = "获取最近24小时电压电流趋势数据（5分钟平均）。折线图")
    @GetMapping("/getVoltageCurrentTrendLast24Hours")
    public ResponseResult<List<VoltageCurrentTrendVO>> getVoltageCurrentTrendLast24Hours(
            @RequestParam(required = false, value = "familyId") String familyId,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "deviceId") Long deviceId,
            @RequestParam(required = false, value = "stationNumber") String stationNumber) {

        Map<String, Object> params = new HashMap<>();
        if (familyId != null && !familyId.isEmpty()) params.put("familyId", familyId);
        if (orgId != null && !orgId.isEmpty()) params.put("orgId", orgId);
        if (deviceId != null && deviceId > 0) params.put("deviceId", deviceId);
        if (stationNumber != null && !stationNumber.isEmpty()) params.put("stationNumber", stationNumber);

        return ResponseResult.ok(dataAnalysisService.getVoltageCurrentTrendLast24Hours(params));
    }

    /**
     * 获取最近1小时的功率对比数据（每分钟平均值），支持家族ID、组织ID、设备ID、站点编号作为可选条件
     *
     * @return 功率对比数据列表
     */
    @Operation(summary = "获取最近1小时的功率对比数据（每分钟平均值）,柱状图")
    @GetMapping("/getPowerComparison")
    public ResponseResult<List<PowerComparisonVO>> getPowerComparison(
            @RequestParam(required = false, value = "familyId") String familyId,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "deviceId") String deviceId,
            @RequestParam(required = false, value = "stationNumber") String stationNumber) {

        Map<String, Object> params = new HashMap<>();
        if (familyId != null && !familyId.isEmpty()) params.put("familyId", familyId);
        if (orgId != null && !orgId.isEmpty()) params.put("orgId", orgId);
        if (deviceId != null && !deviceId.isEmpty()) params.put("deviceId", deviceId);
        if (stationNumber != null && !stationNumber.isEmpty()) params.put("stationNumber", stationNumber);

        return ResponseResult.ok(dataAnalysisService.getPowerComparisonLastHour(params));
    }

    /**
     * 获取功率因数趋势数据，支持家族ID、组织ID、设备ID、站点编号作为可选条件
     *
     * @param familyId      家族ID
     * @param orgId         组织ID
     * @param deviceId      设备ID
     * @param stationNumber 站点编号
     * @param timeRange     时间范围，默认为 24h
     * @param interval      时间间隔，默认为 15 分钟.1分钟、5分钟、15分钟
     * @return 功率因数趋势数据列表
     */
    @Operation(summary = "获取功率因数趋势数据,折线图")
    @GetMapping("/getPowerFactorTrend")
    public ResponseResult<List<PowerFactorTrendVO>> getPowerFactorTrend(
            @RequestParam(value = "familyId", required = false) String familyId,
            @RequestParam(value = "orgId", required = false) String orgId,
            @RequestParam(value = "deviceId", required = false) Long deviceId,
            @RequestParam(value = "stationNumber", required = false) String stationNumber,
            @RequestParam(value = "timeRange", defaultValue = "24h") String timeRange,
            @RequestParam(value = "interval", defaultValue = "15m") String interval) { // 新增时间间隔参数

        Map<String, Object> params = new HashMap<>();
        params.put("familyId", familyId);
        params.put("orgId", orgId);
        params.put("deviceId", deviceId);
        params.put("stationNumber", stationNumber);
        params.put("timeRange", timeRange);
        params.put("interval", interval); // 将时间间隔加入查询条件

        List<PowerFactorTrendVO> trendData = dataAnalysisService.getPowerFactorTrend(params);
        return ResponseResult.ok(trendData);
    }

    /**
     * 获取电能累积趋势（正向有功电度）
     */
    @Operation(summary = "获取电能累积趋势（正向有功电度）")
    @GetMapping("/getEnergyAccumulationTrend")
    public ResponseResult<List<EnergyAccumulationTrendVO>> getEnergyAccumulationTrend(
            @RequestParam(required = false, value = "familyId") String familyId,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "deviceId") Long deviceId,
            @RequestParam(required = false, value = "stationNumber") String stationNumber,
            @RequestParam(defaultValue = "24h", value = "24h") String timeRange,
            @RequestParam(defaultValue = "15m", value = "15m") String interval) {

        Map<String, Object> params = new HashMap<>();
        params.put("familyId", familyId);
        params.put("orgId", orgId);
        params.put("deviceId", deviceId);
        params.put("stationNumber", stationNumber);
        params.put("timeRange", timeRange);
        params.put("interval", interval);

        List<EnergyAccumulationTrendVO> data = dataAnalysisService.getEnergyAccumulationTrend(params);
        return ResponseResult.ok(data);
    }

    /**
     * 用电增量图
     */
    @Operation(summary = "用电增量图")
    @GetMapping("/getEnergyIncrement")
    public ResponseResult<List<EnergyIncrementVO>> getEnergyIncrement(
            @RequestParam(required = false, value = "familyId") String familyId,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "deviceId") Long deviceId,
            @RequestParam(required = false, value = "stationNumber") String stationNumber) {

        Map<String, Object> params = new HashMap<>();
        params.put("familyId", familyId);
        params.put("orgId", orgId);
        params.put("deviceId", deviceId);
        params.put("stationNumber", stationNumber);

        List<EnergyIncrementVO> incrementData = dataAnalysisService.getEnergyIncrementData(params);
        return ResponseResult.ok(incrementData);
    }

    /**
     * 获取峰谷平电量统计数据
     */
    @Operation(summary = "获取峰谷平电量统计数据")
    @GetMapping("/getPeakValleyFlatStats")
    public ResponseResult<List<PeakValleyFlatStatsVO>> getPeakValleyFlatStats(
            @RequestParam(required = false, value = "startTime") String startTime,
            @RequestParam(required = false, value = "endTime") String endTime,
            @RequestParam(required = false, value = "familyId") String familyId,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "deviceId") Long deviceId,
            @RequestParam(required = false, value = "stationNumber") String stationNumber) {

        LocalDateTime startDt, endDt;

        // 如果时间都为空，默认查昨天一整天
        if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime)) {
            LocalDate yesterday = LocalDate.now().minusDays(1);
            startDt = yesterday.atStartOfDay(); // 00:00:00
            endDt = yesterday.atTime(23, 59, 59); // 23:59:59
        } else {
            // 否则尝试解析传入的时间
            try {
                DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                startDt = StringUtils.hasText(startTime) ?
                        LocalDateTime.parse(startTime, fmt) :
                        LocalDate.now().minusDays(1).atStartOfDay();

                endDt = StringUtils.hasText(endTime) ?
                        LocalDateTime.parse(endTime, fmt) :
                        LocalDateTime.now();
            } catch (DateTimeParseException e) {
                throw new IllegalArgumentException("时间格式错误，应为 yyyy-MM-dd HH:mm:ss");
            }
        }

        // 构建参数
        Map<String, Object> params = new HashMap<>();
        params.put("startTime", startDt);
        params.put("endTime", endDt);
        params.put("familyId", familyId);
        params.put("orgId", orgId);
        params.put("deviceId", deviceId);
        params.put("stationNumber", stationNumber);
        params.put("deviceTypes", Arrays.asList("power_meter_10kv"));

        List<PeakValleyFlatStatsVO> stats = dataAnalysisService.getPeakValleyFlatStats(params);
        return ResponseResult.ok(stats);
    }

    /**
     * 获取今日三相不平衡分析数据（按10分钟粒度降采样）
     */
    @Operation(summary = "获取今日三相不平衡分析数据")
    @GetMapping("/getThreePhaseUnbalance")
    public ResponseResult<List<ThreePhaseUnbalanceVO>> getThreePhaseUnbalance(
            @RequestParam(required = false, value = "familyId") String familyId,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "deviceId") String deviceId,
            @RequestParam(required = false, value = "stationNumber") String stationNumber) {

        // 固定为“今天”
        LocalDateTime todayStart = LocalDate.now().atStartOfDay(); // 今天 00:00:00
        LocalDateTime now = LocalDateTime.now();

        Map<String, Object> params = new HashMap<>();
        params.put("familyId", familyId);
        params.put("orgId", orgId);
        params.put("deviceId", deviceId);
        params.put("stationNumber", stationNumber);
        params.put("startTime", todayStart);
        params.put("endTime", now);
        params.put("intervalMinutes", 10); // 每10分钟采样一次

        List<ThreePhaseUnbalanceVO> data = dataAnalysisService.getThreePhaseUnbalanceData(params);
        return ResponseResult.ok(data);
    }

    @Operation(summary = "获取设备日负载率（默认昨天）")
    @GetMapping("/dailyLoadRate")
    public ResponseResult<List<LoadRateStatsVO>> getDailyLoadRate(
            @RequestParam(required = false, value = "startTime") String startTime,
            @RequestParam(required = false, value = "endTime") String endTime,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "deviceId") Long deviceId) {

        // 默认查昨天
        LocalDateTime[] range = getTimeRange(startTime, endTime, true);
        LocalDateTime start = range[0], end = range[1];

        Map<String, Object> params = buildParams(start, end, orgId, deviceId);
        params.put("deviceTypes", Arrays.asList("power_meter_10kv", "power_meter_04kv"));

        List<LoadRateStatsVO> stats = dataAnalysisService.getDailyLoadRate(params);
        return ResponseResult.ok(stats);
    }

    @Operation(summary = "获取分时段负载率（高峰/平时/低谷）")
    @GetMapping("/periodLoadRate")
    public ResponseResult<List<LoadRateStatsVO>> getPeriodLoadRate(
            @RequestParam(required = false, value = "startTime") String startTime,
            @RequestParam(required = false, value = "endTime") String endTime,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "deviceId") Long deviceId) {

        LocalDateTime[] range = getTimeRange(startTime, endTime, true);
        Map<String, Object> params = buildParams(range[0], range[1], orgId, deviceId);
        params.put("deviceTypes", Arrays.asList("power_meter_10kv", "power_meter_04kv"));

        List<LoadRateStatsVO> stats = dataAnalysisService.getPeriodLoadRate(params);
        return ResponseResult.ok(stats);
    }

    @Operation(summary = "获取重载设备排行（负载率>80%）")
    @GetMapping("/overloadedDevices")
    public ResponseResult<List<LoadRateStatsVO>> getOverloadedDevices(
            @RequestParam(required = false, value = "startTime") String startTime,
            @RequestParam(required = false, value = "endTime") String endTime,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(defaultValue = "10", value = "limit") Integer limit) {

        LocalDateTime[] range = getTimeRange(startTime, endTime, true);
        Map<String, Object> params = buildParams(range[0], range[1], orgId, null);
        params.put("deviceTypes", Arrays.asList("power_meter_10kv", "power_meter_04kv"));
        params.put("limit", limit);

        List<LoadRateStatsVO> stats = dataAnalysisService.getOverloadedDevices(params);
        return ResponseResult.ok(stats);
    }

    // 工具方法：构建时间范围
    private LocalDateTime[] getTimeRange(String startTime, String endTime, boolean defaultYesterday) {
        LocalDateTime start, end;
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        if (startTime != null && endTime != null) {
            start = LocalDateTime.parse(startTime, fmt);
            end = LocalDateTime.parse(endTime, fmt);
        } else if (defaultYesterday) {
            LocalDate yesterday = LocalDate.now().minusDays(1);
            start = yesterday.atStartOfDay();
            end = yesterday.atTime(23, 59, 59);
        } else {
            start = LocalDate.now().atStartOfDay();
            end = LocalDateTime.now();
        }
        return new LocalDateTime[]{start, end};
    }

    // 构建公共参数
    private Map<String, Object> buildParams(LocalDateTime start, LocalDateTime end, String orgId, Long deviceId) {
        Map<String, Object> params = new HashMap<>();
        params.put("startTime", start);
        params.put("endTime", end);
        params.put("orgId", orgId);
        params.put("deviceId", deviceId);
        return params;
    }


    @Operation(summary = "获取日电量排行榜")
    @GetMapping("/getDailyEnergyRanking")
    public ResponseResult<List<DailyEnergyRankingDTO>> getDailyEnergyRanking(
            @RequestParam("date") String date,
            @RequestParam(value = "orgId", required = false) String orgId,
            @RequestParam(value = "stationNumber", required = false) Long stationNumber,
            @RequestParam(value = "limit", required = false) Integer limit) {

        List<DailyEnergyRankingDTO> data = dataAnalysisService.getDailyEnergyRanking(date, orgId, stationNumber, limit);
        return ResponseResult.ok(data);
    }

    @Operation(summary = "获取配电房环境温度，温湿度折线图")
    @GetMapping("/getTemperatureHumidityTrend")
    public ResponseResult<List<TemperatureHumidityData>> getTemperatureHumidityTrend(
            @RequestParam(value = "familyId", required = false) String familyId,
            @RequestParam(value = "orgId", required = false) String orgId,
            @RequestParam(value = "deviceId", required = false) Long deviceId,
            @RequestParam(value = "stationNumber", required = false) Long stationNumber) {

        return ResponseResult.ok(dataAnalysisService.getTemperatureHumidityTrend(familyId, orgId, deviceId, stationNumber));
    }

    @Operation(summary = "烟雾、水浸、入侵：绿色（正常）/红色（告警)")
    @GetMapping("/getAlarmStatus")
    public ResponseResult<AlarmStatusData> getAlarmStatus(
            @RequestParam(value = "familyId", required = false) String familyId,
            @RequestParam(value = "orgId", required = false) String orgId,
            @RequestParam(value = "deviceId", required = false) Long deviceId,
            @RequestParam(value = "stationNumber", required = false) Long stationNumber) {

        return ResponseResult.ok(dataAnalysisService.getAlarmStatus(familyId, orgId, deviceId, stationNumber));
    }

    /**
     * 获取配电房温度热力图数据
     * GET /api/heatmap/temperature?deviceTypes=配电房环境监测&orgIds=org1,org2&familyId=fam1
     */
    @Operation(summary = "获取配电房温度热力图数据")
    @GetMapping("/getTemperatureHeatmap")
    public ResponseResult<List<TemperatureHeatmapItem>> getTemperatureHeatmap(
            @RequestParam(value = "orgId", required = false) String orgId,
            @RequestParam(value = "familyId", required = false) String familyId) {

        return ResponseResult.ok(dataAnalysisService.getTemperatureHeatmapData(orgId, familyId));
    }

    @Operation(summary = "获取配电房湿度热力图数据")
    @GetMapping("/getHumidityHeatmapData")
    public ResponseResult<List<HumidityHeatmapData>> getHumidityHeatmapData(@RequestParam(value = "orgId", required = false) String orgId,
                                                                            @RequestParam(value = "familyId", required = false) String familyId) {
        return ResponseResult.ok(dataAnalysisService.getHumidityHeatmapData(orgId, familyId));
    }

    /**
     * 获取断路器状态历史数据
     * GET /api/breaker/history?orgId=org1&deviceId=dev1&breakerNum=1&startTime=2022-01-01T00:00:00&endTime=2022-01-01T23:59:59
     */
    @Operation(summary = "获取断路器状态历史数据(微机保护)")
    @GetMapping("/getBreakerStatusHistory")
    public ResponseResult<List<BreakerStatusRecord>> getBreakerStatusHistory(
            @RequestParam(value = "orgId", required = true) String orgId,
            @RequestParam(value = "stationNumber", required = true) Long stationNumber,
            @RequestParam(value = "breakerNum", required = true) Integer breakerNum,
            @RequestParam(value = "deviceId", required = true) Long deviceId,
            @RequestParam(required = false, value = "startTime")
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
            LocalDateTime startTime,
            @RequestParam(required = false, value = "endTime")
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
            LocalDateTime endTime) {
        // 设置默认时间范围：最近24小时
        LocalDateTime now = LocalDateTime.now();
        if (startTime == null && endTime == null) {
            startTime = now.minusHours(24);  // 默认：24小时前 → 现在
            endTime = now;
        } else if (startTime == null) {
            startTime = endTime.minusHours(24); // 只传 endTime，往前推24小时
        } else if (endTime == null) {
            endTime = startTime.plusHours(24); // 只传 startTime，往后推24小时
        }

        // 防止时间倒序
        if (startTime.isAfter(endTime)) {
            throw new IllegalArgumentException("开始时间不能晚于结束时间");
        }

        List<BreakerStatusRecord> records = dataAnalysisService.getBreakerStatusHistory(
                orgId, stationNumber, deviceId, breakerNum, startTime, endTime);

        return ResponseResult.ok(records);
    }

    @Operation(summary = "分析断路器跳闸事件（支持过流判断）")
    @GetMapping("/analyzeTripEvents")
    public ResponseResult<List<TripEvent>> analyzeTripEvents(
            @RequestParam(value = "orgId", required = true) String orgId,
            @RequestParam(value = "stationNumber", required = true) Long stationNumber,
            @RequestParam(value = "deviceId", required = true) Long deviceId,
            @RequestParam(value = "breakerNum", required = true) Integer breakerNum,
            @RequestParam(required = false, value = "startTime")
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
            @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            LocalDateTime startTime,
            @RequestParam(required = false, value = "endTime")
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
            @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            LocalDateTime endTime,
            @RequestParam(required = true, value = "currentThreshold")
            @Parameter(description = "过流跳闸电流阈值（单位：安培）")
            BigDecimal currentThreshold,
            @RequestParam(required = true, value = "timeWindowSeconds")
            @Parameter(description = "电流突增到跳闸的时间窗口（秒）")
            Long timeWindowSeconds) {

        // 设置默认时间范围：最近24小时
        LocalDateTime now = LocalDateTime.now();
        if (startTime == null && endTime == null) {
            startTime = now.minusHours(24);
            endTime = now;
        } else if (startTime == null) {
            startTime = endTime.minusHours(24);
        } else if (endTime == null) {
            endTime = startTime.plusHours(24);
        }

        if (startTime.isAfter(endTime)) {
            throw new IllegalArgumentException("开始时间不能晚于结束时间");
        }

        // 获取历史数据
        List<BreakerStatusRecord> records = dataAnalysisService.getBreakerStatusHistory(
                orgId, stationNumber, deviceId, breakerNum, startTime, endTime);

        // 分析跳闸事件
        List<TripEvent> tripEvents = dataAnalysisService.analyzeTripEvents(records, currentThreshold, timeWindowSeconds);

        return ResponseResult.ok(tripEvents);
    }

    @GetMapping("/getThreePhaseTemperatureTrend")
    @Operation(summary = "三相温度折线图（A/B/C相温度趋势对比）")
    public ResponseResult<List<ThreePhaseTemperatureDTO>> getThreePhaseTemperatureTrend(
            @RequestParam(required = false, value = "deviceId") Long deviceId,
            @RequestParam(required = false, value = "familyId") String familyId,
            @RequestParam(required = false, value = "orgId") String orgId,
            @RequestParam(required = false, value = "stationNumber") Long stationNumber,
            @RequestParam(required = false, value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
            @RequestParam(required = false, value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime) {

        List<ThreePhaseTemperatureDTO> data = dataAnalysisService.getThreePhaseTemperatureTrend(deviceId, familyId, orgId, stationNumber, startTime, endTime);

        return ResponseResult.ok(data);
    }

    /**
     * 获取多台变压器24小时内温度对比（柱状图）
     * GET /api/data-analysis/transformer-temp-comparison?orgId=xxx&deviceTypes=变压器温控仪
     */
    @GetMapping("/getTransformerTemperatureComparison")
    @Operation(summary = "获取多台变压器24小时内温度对比（柱状图）")
    public ResponseResult<Map<String, Object>> getTransformerTemperatureComparison(
            @RequestParam("orgId") String orgId,
            @RequestParam(value = "stationNumber", required = false) Long stationNumber) {
        return ResponseResult.ok(dataAnalysisService.getMultiTransformerTemperatureComparison(orgId, stationNumber));
    }

    /**
     * 获取无线测温主机三相电缆温度趋势（24小时）
     */
    @Operation(summary = "获取无线测温主机三相电缆温度趋势（24小时）")
    @GetMapping("/getWirelessHostCableTempTrend")
    public ResponseResult<Map<String, Object>> getWirelessHostCableTempTrend(
            @RequestParam("orgId") String orgId,
            @RequestParam(value = "deviceIds", required = false) List<Long> deviceIds,
            @RequestParam(value = "stationNumber", required = false) Long stationNumber) {

        return ResponseResult.ok(dataAnalysisService.getWirelessHostCableTempTrend(orgId, deviceIds, stationNumber));
    }

    @Operation(summary = "获取无线测温主机三相温度最高排名，top10")
    @GetMapping("/getCableTemperatureTop10")
    public ResponseResult<Map<String, Object>> getCableTemperatureTop10(
            @RequestParam("orgId") String orgId,
            @RequestParam(value = "stationNumber", required = false) Long stationNumber) {

        return ResponseResult.ok(dataAnalysisService.getCableTemperatureTop10(orgId, stationNumber));
    }


    /**
     * 获取驾驶舱全部 KPI 数据
     */
    @Operation(summary = "获取企业驾驶舱小卡片数据")
    @GetMapping("/getDashboardKpi")
    public ResponseResult<DashboardKpiDTO> getDashboardKpi(@RequestParam("orgId") String orgId) {
        DashboardKpiDTO data = dataAnalysisService.getDashboardKpi(orgId);
        return ResponseResult.ok(data);
    }

    /**
     * 统计配电房、配电箱和设备的数量
     */
    @Operation(summary = "统计配电房、配电箱和设备的数量")
    @GetMapping("/getCounts")
    public ResponseResult<Map<String, Object>> getCounts(@RequestParam("orgId") String orgId) {
        return ResponseResult.ok(dataAnalysisService.getCounts(orgId));
    }
}
